import z from "zod";

// 创建菜品验证schema
export const CreateDishesRequestSchema = z.object({
  categoryId: z.number().positive("菜品id为正整数"),
  name: z.string().min(2, "菜品名称至少2个字").max(10, "菜品名称最多10个字"),
  description: z.string().default(""),
  picture: z.string().min(5, "图片地址字符数小于5"),
  thumbnail: z.string().min(5, "图片地址字符数小于5"),
});

export type CreateDishesRequestDTO = z.infer<typeof CreateDishesRequestSchema>;

// 更新菜品验证schema
export const UpdateDishesRequestSchema = z
  .object({
    categoryId: z.number().positive("菜品id为正整数").optional(),
    name: z
      .string()
      .min(2, "菜品名称至少2个字")
      .max(10, "菜品名称最多10个字")
      .optional(),
    description: z.string().optional(),
    picture: z.string().min(5, "图片地址字符数小于5").optional(),
    thumbnail: z.string().min(5, "图片地址字符数小于5").optional(),
  })
  .refine((obj) => Object.values(obj).some((value) => value !== undefined), {
    message: "至少提供一个要更新的字段",
  });

export type UpdateDishesRequestDTO = z.infer<typeof UpdateDishesRequestSchema>;

// 菜品评分验证schema
export const DishesIdListRequestSchema = z.object({
  dishesIdList: z.array(z.number().int().positive("菜品id为正整数")),
});

export type DishesIdListRequestDTO = z.infer<typeof DishesIdListRequestSchema>;
